package com.zhf.controller;

import com.zhf.domain.Course;
import com.zhf.domain.CourseSection;
import com.zhf.domain.ResponseResult;
import com.zhf.service.CourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/12/2 23:08
 */
@RestController
@RequestMapping("/courseContent")
public class CourseConrtentController {

    @Autowired
    private CourseContentService courseContentService;

    @RequestMapping("/findSectionAndLesson")
    public ResponseResult findSectionAndLesson(Integer courseId){
        List<CourseSection> list = courseContentService.findSectionAndLessonByCourseId(courseId);
        ResponseResult result = new ResponseResult(true, 200, "章节及课时内容查询成功", list);

        return result;
    }

    @RequestMapping("/findCourseByCourseId")
    public ResponseResult findCourseByCourseId(Integer courseId){
        Course course = courseContentService.findCourseByCourseId(courseId);
        ResponseResult result = new ResponseResult(true, 200, "查询课程信息成功", course);

        return result;
    }

    @RequestMapping("/saveOrUpdateSection")
    public ResponseResult saveOrUpdateSection(@RequestBody CourseSection courseSection){
        if (courseSection.getId()==null){
            courseContentService.saveSection(courseSection);
            ResponseResult result = new ResponseResult(true, 200, "新增章节成功", null);
            return result;
        }else{
            courseContentService.updateSection(courseSection);
            ResponseResult result = new ResponseResult(true, 200, "更新章节成功", null);
            return result;
        }
    }

    @RequestMapping("/updateSectionStatus")
    public ResponseResult updateSectionStatus(int id,int status){
        courseContentService.updateSectionStatus(id, status);
        HashMap<String, Integer> map = new HashMap<>();
        map.put("status",status);
        ResponseResult result = new ResponseResult(true, 200, "更新状态成功", map);
        return result;
    }
}
